package com.ruoyi.web.petmall.petback.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.petmall.entity.AddressEntity;
import com.ruoyi.web.petmall.entity.OrderEntity;
import com.ruoyi.web.petmall.petback.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value ="/petBack/order")
@Api(tags = "订单管理")
public class OrderController extends BaseController {


    @Autowired
    private OrderService orderService;

    /**
     * 分页查询订单信息
     *
     * @param orderEntity 查询条件封装为 OrderEntity 对象
     * @return 包含分页结果的 TableDataInfo 对象
     */
    @ApiOperation("分页查询订单信息")
    @GetMapping("/getOrderList")
    public TableDataInfo getOrderList(OrderEntity orderEntity) {
        startPage();
        List<OrderEntity> list = orderService.getOrderList(orderEntity);
        return getDataTable(list);
    }

    /**
     * 修改订单信息
     *
     * @param orderEntity 要修改的订单信息封装为 OrderEntity 对象
     * @return 包含操作结果的 AjaxResult 对象
     */
    @ApiOperation("修改订单信息")
    @PostMapping("/updateOrderList")
    public AjaxResult updateOrderList(@RequestBody OrderEntity orderEntity) {
        return toAjax(orderService.updateOrderList(orderEntity));
    }

    /**
     * 删除订单
     *
     * @param id 要删除的订单 ID
     * @return 包含操作结果的 AjaxResult 对象
     */
    @ApiOperation("删除订单")
    @DeleteMapping("/deleteOrder")
    public AjaxResult deleteOrder(Long id) {
        return toAjax(orderService.deleteOrder(id));
    }
}
